package com.pw.study.leetcode;

import java.util.HashMap;

/**
 * @Desc: 两数之和
 * @author: future
 * @since: 2022/5/16-22:25
 */
public class $1_numSum {
    public static void main(String[] args) {
        int[] nums={2,7,11,15};
        int target=9;
        int[] arr= test(nums,target);
        printlt(arr);
    }

    private static void printlt(int[] arr) {
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    private static int[] test(int[] nums,int target) {
        HashMap<Integer,Integer> map = new HashMap();
        for (int i = 0; i <nums.length ; i++) {
            if(map.containsKey(target-nums[i])){
                return new int[]{map.get(target-nums[i]),i};
            }
            map.put(nums[i],i);
        }
        return new int[0];
    }

}
